const app = getApp()
var requestApi = require('../../request/requestApi')
var util = require('../../utils/util.js');
Page({
    data: {
        isIphoneX: false,
        screenWidth: '',
        screenHeight: '',
        list:[],
        pageno:1,
        isPageNext:true,

    },

    onLaunch: function () {

    },
    onLoad: function () {

        var that = this;

        //修改封面图宽高
        this.configDataFromNetwork();
        var wxGetSystemInfo=requestApi.wxGetSystemInfo()
        wxGetSystemInfo().then(res=>{
            var windowWidth = res.windowWidth;
            var windowHeight = res.windowHeight;
            if (util.systemInfoToPhoneHeightIsX(res)=='X') {
                that.setData({
                    isIphoneX: true,
                })
            } else if(util.systemInfoToPhoneHeightIsX(res)=='N'){
                that.setData({
                    isIphoneX: false,
                })
            }
            that.setData({
                screenWidth: windowWidth,
                screenHeight:windowHeight,
            })
        })



    },
    onReachBottom: function (){
        if ( this.data.isPageNext ){
            this.data.pageno++;
            this.configDataFromNetwork();
        } else{
            return;
        }

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function() {

    },
    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {


    },
    configDataFromNetwork:function () {
        var that = this;
        wx.showLoading({
            title: '加载中',
        });
        requestApi.kukeGetCardList(this.data.pageno,10).then(res=>{
            console.log('configDataFromNetwork-----------------')
            console.log(res)
            that.data.list = res.data.data
            var listNetData = res.data.data;
            if (listNetData<10){
                that.data.isPageNext = false;
            }
            for (var i = 0; i<listNetData.length;i++){
                that.data.list[i].cardImg = listNetData[i].img;
                that.data.list[i].cardTitle = listNetData[i].title;
                if (listNetData[i].ctitle != ''
                    && typeof listNetData[i].ctitle != 'undefined'
                    && listNetData[i].ctitle != undefined) {
                    that.data.list[i].cardTitle = listNetData[i].ctitle;
                }
                that.data.list[i].cardId = listNetData[i].card_id;
                that.data.list[i].cardDetail = listNetData[i].introduce;
                that.data.list[i].itemCode = listNetData[i].item_code;
                that.data.list[i].workId = listNetData[i].work_id;
                that.setData({ list: that.data.list })
            }
            wx.hideLoading();
        })

    },
    clickToNavigation:function (e) {
        // console.log(e)
        if (e.currentTarget.dataset.type == 'back'){
            wx.navigateBack({
                //保留当前页面，跳转到应用内的某个页面（最多打开5个页面，之后按钮就没有响应的）
                delta:1
            })
        }
        if (e.currentTarget.dataset.type == 'cardDetail'){
            wx.navigateTo({
                //保留当前页面，跳转到应用内的某个页面（最多打开5个页面，之后按钮就没有响应的）
                url:"/pages/cardDetail/cardDetail?cardId="+e.currentTarget.dataset.id
            })
        }
    }
})
